/**
 * Class adopted and tweaked from Svetlin Nakov's class of the same name.
 * Svetlin Nakov: http://www.nakov.com.
 */
package com.celephais.common.client.model;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * @author Eugene Shen
 * Represents a column / field in a TransportableObject.
 */
public class TableColumn implements IsSerializable {

	// TODO: Add references, etc. here.
	public static enum DisplayType { TEXT_BOX, TEXT_AREA, CHECK_BOX, LIST_BOX, CHILD, REFERENCE };
	
	private String name;
	private String title;
	// TODO: Split this to "Display" and "Edit"?
	private boolean show;
	private DisplayType displayType;
	private String[] validValues;
	
	public TableColumn() {
		super();
		setName("");
		setTitle("");
		setShow(false);
		setDisplayType(DisplayType.TEXT_BOX);
		setValidValues(null);
	}
	
	public TableColumn(String name, String title, boolean show,
			DisplayType displayType, String... validValues) {
		super();
		setName(name);
		setTitle(title);
		setShow(show);
		setDisplayType(displayType);
		setValidValues(validValues);
	}

	// Copy Constructor
	public TableColumn(TableColumn from) {
		super();
		setName(from.getName());
		setTitle(from.getTitle());
		setShow(from.isShow());
		setDisplayType(from.getDisplayType());
		
		String[] fromVV = from.getValidValues();
		if (fromVV != null && fromVV.length > 0) {
			String[] toVV = new String[fromVV.length];
			for (int i=0; i<toVV.length; ++i) {
				toVV[i] = fromVV[i];
			}
			setValidValues(toVV);
		}
	}
	
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	public String getTitle() {
		return title;
	}

	public void setShow(boolean show) {
		this.show = show;
	}
	public boolean isShow() {
		return show;
	}

	public void setDisplayType(DisplayType displayType) {
		this.displayType = displayType;
	}
	public DisplayType getDisplayType() {
		return displayType;
	}

	public void setValidValues(String[] validValues) {
		this.validValues = validValues;
	}
	public String[] getValidValues() {
		return validValues;
	}
}
